/*******************
Figure 3. Event Study: Effect of Uber Entry on Self-Employment Response to the EITC
*******************/
use "data\hslesshousehold_ubereitc2005_2019", clear

gen uberyr = year(DateofEntry)
bys stfips: egen stuberyr = min(uberyr)
gen uber = uberyr ~= .
gen tyr = year-uberyr if uber == 1 
replace tyr = year-stuberyr if uber == 0 

forval i = 1/5 {
	gen tyr_neg`i' = tyr == -`i'
	gen tyr_pos`i' = tyr == `i'
	
	gen maxeitc_tyr_neg`i' = max_total_credit2020*tyr_neg`i'
	gen maxeitc_tyr_pos`i' = max_total_credit2020*tyr_pos`i'
	
	gen maxeitc_uber_tyr_neg`i' = max_total_credit2020*uber*tyr_neg`i'
	gen maxeitc_uber_tyr_pos`i' = max_total_credit2020*uber*tyr_pos`i'
	
	gen uber_tyr_neg`i' = uber*tyr_neg`i'
	gen uber_tyr_pos`i' = uber*tyr_pos`i'
}

gen maxeitc_uber = max_total_credit2020*uber

gen tyr_0 = tyr == 0
gen maxeitc_tyr_0 = max_total_credit2020*tyr_0
gen maxeitc_uber_tyr_0 = max_total_credit2020*uber*tyr_0
gen uber_tyr_0 = uber*tyr_0


reghdfe selfemp maxeitc_uber_tyr_neg5 maxeitc_uber_tyr_neg4 maxeitc_uber_tyr_neg3 maxeitc_uber_tyr_neg2 o.maxeitc_uber_tyr_neg1 maxeitc_uber_tyr_0 maxeitc_uber_tyr_pos1 maxeitc_uber_tyr_pos2 maxeitc_uber_tyr_pos3 maxeitc_uber_tyr_pos4 maxeitc_uber_tyr_pos5 ///
maxeitc_tyr_neg5 maxeitc_tyr_neg4 maxeitc_tyr_neg3 maxeitc_tyr_neg2 o.maxeitc_tyr_neg1 maxeitc_tyr_0 maxeitc_tyr_pos1 maxeitc_tyr_pos2 maxeitc_tyr_pos3 maxeitc_tyr_pos4 maxeitc_tyr_pos5 max_total_credit2020 [pw = hhwt] if abs(tyr)<=5 & head_hsorless == 1 & hh_married == 0, absorb(st_yr cbsa_id num_ekids) vce(cluster stfips)
est store e_selfemp2


coefplot (e_selfemp2,  mcolor(navy) ciopts(lcolor(navy))) ///
		, nooffsets keep(maxeitc_uber_tyr_*) yline(0, lcolor(black)) xline(6, lcolor(black) lpattern(__)) omit vertical ///
		ytitle("Effect of $1,000 Increase in Max EITC") ///
		rename(maxeitc_uber_tyr_neg5 = "t-5" maxeitc_uber_tyr_neg4 = "t-4" maxeitc_uber_tyr_neg3 = "t-3" ///
		maxeitc_uber_tyr_neg2 = "t-2" maxeitc_uber_tyr_neg1 = "t-1" maxeitc_uber_tyr_0 = "t=0" maxeitc_uber_tyr_pos1 = "t+1" maxeitc_uber_tyr_pos2 = "t+2" maxeitc_uber_tyr_pos3 = "t+3" maxeitc_uber_tyr_pos4 = "t+4" maxeitc_uber_tyr_pos5 = "t+5" ) ///
		xtitle("Years from Uber Entry") graphregion(color(white)) legend(order(2 "Max EITC ($1,000) in Uber vs. Non-Uber") rows(1) pos(6)) xlabel(,labsize(*.8))
graph export "output\selfemp_dddeventstudy.pdf", replace
